package com.trendwise.software;

import java.io.IOException;
import java.util.Date;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class WebMapper extends Mapper<LongWritable,Text,DateWritable,IntWritable>{

	public static DateWritable dw=new DateWritable();
	public static final IntWritable two=new IntWritable(1);
	
	@Override
	protected void map(LongWritable key, Text value,
			Mapper<LongWritable, Text, DateWritable, IntWritable>.Context context)
			throws IOException, InterruptedException {
		// TODO 자동 생성된 메소드 스텁
		//111.11.111.111 - - [16/Dec/2012:05:32:50 -0500] "GET / HTTP/1.1" 200 14791 "-" "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
		String text=value.toString();
		int beginIndex=text.indexOf('['),endIndex=text.indexOf(']');
		if(beginIndex==-1||endIndex==-1)return;
		
		String dstr=text.substring(beginIndex+1, endIndex);
		
		Date date=DateWritable.parse(dstr);
		
		dw.setDate(date);
		
		context.write(dw, two);
	}

}
